const http = require('http')

const sc = {
  formid: '5846bcc7-63fd-49a6-a774-48728b349491',
  title: '会员信息登记',
  label: '活动说明',
  bgurl: 'https://www.lanpiankeji.com/weixinNotify/images/autoform/yy_form_bg.png',
  description: '活动说明',
  endtime: '2023-12-31',
  total: 20,
  ismodify: true,
  // smscheck: true,
  smscycle: 60,
  components: [
    { id: '001', type: 'textInput', model: 'name', labelWidth: '70', label: '会员姓名', placeholder: '请输入真实姓名，以便校对', ruletype: 'withoutNum' },
    // { id: '011', type: 'phoneCheck', model: 'phone', labelWidth: '70', label: '手机号码', placeholder: '确保手机号能联系到您', ruletype: 'PhoneNum' },
    { id: '021', type: 'textInput', model: 'idcard', label: '身份证号', labelWidth: '70', placeholder: '以此发送生日祝福' },
    {
      id: '004',
      type: 'radio',
      model: 'gender',
      label: '性   别',
      labelWidth: '70',
      defaultval: '男',
      opts: [
        { name: '男', disabled: false },
        { name: '女', disabled: false },
      ],
    },
    {
      id: '023',
      type: 'radio',
      model: 'height',
      label: '身高(CM)',
      labelWidth: '70',
      ruletype: 'Required',
      placeholder: '用于统计衣服尺寸',
      placement: 'column',
      opts: [
        { name: '155-170', disabled: false },
        { name: '165-175', disabled: false },
        { name: '170-180', disabled: false },
        { name: '175-185', disabled: false },
        { name: '180-190', disabled: false },
      ],
    },
    {
      id: '024',
      type: 'radio',
      model: 'weight',
      label: '体重(KG)',
      ruletype: 'Required',
      labelWidth: '70',
      placement: 'column',
      opts: [
        { name: '50-60', disabled: false },
        { name: '60-75', disabled: false },
        { name: '70-85', disabled: false },
        { name: '80-95', disabled: false },
        { name: '90-105', disabled: false },
      ],
      placeholder: '用于统计衣服尺寸',
    },
    {
      id: '003',
      type: 'checkbox',
      model: 'like',
      label: '最擅长的泳姿',
      placement: 'column',
      labelWidth: '120',
      opts: [
        { name: '自由泳', disabled: false },
        { name: '蛙泳', disabled: false },
        { name: '蝶泳', disabled: false },
        { name: '仰泳', disabled: false },
      ],
    },
  ],
}
const formid = '5846bcc7-63fd-49a6-a774-48728b349491'
const script = `update formlist set [schema]='${JSON.stringify(sc)}' where id = '${formid}';`

const postData = JSON.stringify({ script })
const options = {
  hostname: 'www.ywjdzb.cn',
  port: 80,
  path: '/weixinNotify/AutoForm/AddItem',
  method: 'POST',
  headers: {
    'Content-Type': 'application/json;charset=utf-8',
  },
}

const req = http.request(options, (res) => {
  console.log(`状态码: ${res.statusCode}`)
  res.on('data', (chunk) => {
    console.log(`响应主体: ${chunk}`)
  })
  res.on('end', () => {
    console.log('响应中已无数据')
  })
})

req.on('error', (error) => {
  console.error(`请求遇到问题: ${error.message}`)
})

req.write(postData)
req.end()
